package eu.jba.denshijisho.listeners;

import android.graphics.Color;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

public class ListenersHelper {
	
	private static Integer selectedItemPosition;
	private static String selectedType; 


	public static OnItemClickListener getListViewItemListener(){
		return new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if (selectedItemPosition == null
						|| selectedItemPosition != position) {
					view.setSelected(true);
					for (int i = 0; i < parent.getChildCount(); i++) {
						parent.getChildAt(i).setBackgroundColor(Color.BLACK);
					}
					view.setBackgroundColor(Color.DKGRAY);
					selectedItemPosition = position;
				} else {
					view.setSelected(false);
					view.setBackgroundColor(Color.BLACK);
					selectedItemPosition = null;
				}
			}
		};
	}
	
	public static OnItemSelectedListener getSelectType(){
		return new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				selectedType = (String)parent.getItemAtPosition(position);				
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
			}
		};
	}
	
	public static String getSelectedType(){
		return selectedType;
	}
	
}
